/*	This program produces Appendix Table D.8 */

***** Set directories 
local dir_clean 	"~/Dropbox/Retirement gaming/clean"
local dir_output 	"~/Dropbox/Retirement gaming/output/dataverse"


use "`dir_clean'/firmsample_age50.dta", clear

local listcontrols = " i.t i.ciiu2 i.fsize i.year#i.ciiu2 i.year#i.fsize "  

* Panel A
estimates clear
preserve
keep if match==1
foreach Y in i50plus_any Wr Wp i W   { 	
	*Normalize outcome
	sum `Y' if zyearsjt==-1
	local mean=r(mean)
	g `Y'z=(`Y'-`mean')/`mean'
	if "`Y'"=="i50plus_any"  { 
		replace `Y'z=`Y'
	}	
	* Regress
	eststo: reghdfe `Y'z zpre48 zpost5053 zpost54, absorb(`listcontrols') vce(cluster j) 
}
restore
esttab using "`dir_output'/tableD8a.tex", ///
	keep(zpre48 zpost5053 zpost54)  noobs sfmt(%9.0f) ///
	b(%4.3f) se(%4.3f) star(* 0.10 ** 0.05 *** 0.01) ///
	f nomtitles  nogaps replace label  nonumbers nolines

* Panel B	
estimates clear	
preserve
keep if match==1	
foreach Y in i50plus_any Wr Wp i W { 	
	*Normalize outcome
	sum `Y' if zyearsjt==-1
	local mean=r(mean)
	g `Y'z=(`Y'-`mean')/`mean'
	if "`Y'"=="i50plus_any"   { 
		replace `Y'z=`Y'
	}	
	* Regress
	eststo: reghdfe `Y'z zage zpost50 zage_post50, absorb(`listcontrols') vce(cluster j ) 
}	
restore
esttab using "`dir_output'/tableD8b.tex", ///
	keep(zpost* zage*)  scalars("N Observations" "N_clust1 NrFirms") sfmt(%9.0f) ///
	b(%4.3f) se(%4.3f) star(* 0.10 ** 0.05 *** 0.01) ///
	f nomtitles  nogaps replace label nonumbers nolines prefoot(\hline) 


clear all
exit
